package com.itheima.dao;

import com.itheima.domain.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

@Repository
public class AccountDao {


    public void add(int id, double money, Connection connection){

        try {


            PreparedStatement preparedStatement = connection.prepareStatement("update account set money=money+? where id=?");

            preparedStatement.setDouble(1,money);
            preparedStatement.setInt(2,id);
            preparedStatement.execute();


        } catch (SQLException e) {

            throw new RuntimeException(e);
        }


    }
    public void sub(int id,double money,Connection connection){

        try {


            PreparedStatement preparedStatement = connection.prepareStatement("update account set money=money-? where id=?");

            preparedStatement.setDouble(1,money);
            preparedStatement.setInt(2,id);
            preparedStatement.execute();



        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }


    public void save(Account account) {
        System.out.println("完成了插入功能");
    }

    public void delete(int id) {
        System.out.println("完成了删除功能");
    }

    public Account findById(int id) {
        System.out.println("完成了查找功能");
        return null;
    }
}
